import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import Yuangong from '../components/user/Yuangong.vue'
import Juese from '../components/user/Juese.vue';
import Bumen from '../components/user/Bumen.vue'
import Carlist from '../components/car/Carlist.vue'
import Carbaoxian from '../components/car/Carbaoxian.vue'
import Carrenwu from '../components/car/Carrenwu.vue'
import Churutaizhang from '../components/finace/Churutaizhang.vue'
import Jihuajiesuan from '../components/finace/Jihuajiesuan.vue'
import Niandu from '../components/finace/Niandu.vue'
import Kucunchaxun from '../components/inventory/Kucunchaxun.vue'
import Wuliaoguanli from '../components/inventory/Wuliaoguanli.vue'
import Beipinjihua from '../components/plan/Beipinjihua.vue'
import Dianlan from '../components/plan/Dianlan.vue'
import Xinpin from '../components/plan/Xinpin.vue'
import Planlist from '../components/plan/Planlist.vue'
import Cangkushezhi from '../components/repository/Cangkushezhi.vue'
import Kuweishezhi from '../components/repository/Kuweishezhi.vue'
import Zhuanyijilu from '../components/repository/Zhuanyijilu.vue'
import Biandian from '../components/statistics/Biandian.vue'
import Chuche from '../components/statistics/Chuche.vue'
import Daoxian from '../components/statistics/Daoxian.vue'
import Dianlantongji from '../components/statistics/Dianlantongji.vue'
import Renyuanrenwutj from '../components/statistics/Renyuanrenwutj.vue'
import Wuliaotongji from '../components/statistics/Wuliaotongji.vue'
import Xinpintongji from '../components/statistics/Xinpintongji.vue'
import index from '../components/index.vue'
import Ckujiankong from '../components/repository/Ckujiankong.vue'
import CarMap from '../components/car/CarMap.vue'
import NotFound from '../views/404.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path:'/login',
    name:'Login',
    component:Login
  },
  {
    path:'/404',
    name:'NotFound',
    component:NotFound
  },
  {
    path:'*',
    redirect:'/404'
  },
  {
    path:'/home',
    name:Home,
    component:Home,
    redirect:'/home/index',
    children:[
      {path:'/home/index',component:index},
      {path:'/home/yuangong',component:Yuangong},
      {path:'/home/juese',component:Juese},
      {path:'/home/bumen',component:Bumen},
      {path:'/home/carlist',component:Carlist},
      {path:'/home/carbaoxian',component:Carbaoxian},
      {path:'/home/carrenwu',component:Carrenwu},
      {path:'/home/churutaizhang',component:Churutaizhang},
      {path:'/home/jihuajiesuan',component:Jihuajiesuan},
      {path:'/home/niandu',component:Niandu},
      {path:'/home/kucunchaxun',component:Kucunchaxun},
      {path:'/home/wuliaoguanli',component:Wuliaoguanli},
      {path:'/home/beipinjihua',component:Beipinjihua},
      {path:'/home/dianlan',component:Dianlan},
      {path:'/home/xinpin',component:Xinpin},
      {path:'/home/planlist',component:Planlist},
      {path:'/home/cangkushezhi',component:Cangkushezhi},
      {path:'/home/ckujiankong',component:Ckujiankong},
      {path:'/home/kuweishezhi',component:Kuweishezhi},
      {path:'/home/zhuanyijilu',component:Zhuanyijilu},
      {path:'/home/biandian',component:Biandian},
      {path:'/home/chuche',component:Chuche},
      {path:'/home/daoxian',component:Daoxian},
      {path:'/home/dianlantongji',component:Dianlantongji},
      {path:'/home/renyuanrenwutj',component:Renyuanrenwutj},
      {path:'/home/wuliaotongji',component:Wuliaotongji},
      {path:'/home/xinpintongji',component:Xinpintongji},
      {path:'/home/carmap',component:CarMap}
  ]
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
// 路由守卫
router.beforeEach((to,form,next)=>{
  if(to.path==='/login'|| to.path==='/') return next()
  const tokenValue=window.sessionStorage.getItem('token')
  if(!tokenValue) return next('/login')
  next()
})

export default router
